package zhongbo.java.air.dictionary.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;
import zhongbo.java.air.dictionary.model.AirAirCraft;
import zhongbo.java.air.dictionary.service.IAirCraftService;

import javax.validation.Valid;


/**
 * 飞机基础信息表(AirAircraft)表控制层
 *
 * @author makejava
 * @since 2025-03-31 14:02:24
 */
@RestController
@RequestMapping("/airCraft")
@Api(tags = "飞机基础信息接口")
public class AirAircraftController {
    /**
     * 服务对象
     */
    @Autowired
    private IAirCraftService<AirAirCraft> airCraftService;

//    @GetMapping("/queryByPage")
    @GetMapping("findPage")
    @ApiOperation("分页查询飞机信息")
    public ResultVo<PageVo<AirAirCraft>> queryByPage(Integer page, Integer pageSize
            , String keyword, String fields
            , String oderByField, Boolean orderByAsc) {
        PageVo<AirAirCraft> airCraftPageVo = airCraftService.queryByPage(page, pageSize, keyword, fields, oderByField, orderByAsc);
        return ResultVo.ok(airCraftPageVo);
    }

//    @GetMapping("/selectById/{id}")
    @GetMapping("findOne")
    @ApiOperation("根据id查询飞机信息")
    public ResultVo<AirAirCraft> queryById(String entityId) {
        AirAirCraft airAirCraft = airCraftService.queryById(entityId);
        return ResultVo.ok(airAirCraft);
    }


    @PostMapping("/add")
    @ApiOperation("添加飞机信息")
    public ResultVo<AirAirCraft> add(@RequestBody @Valid AirAirCraft airAircraft) {
        AirAirCraft insert = airCraftService.insert(airAircraft);
        return ResultVo.ok(insert);
    }

    @PostMapping("/edit")
    @ApiOperation("修改飞机信息")
    public ResultVo<AirAirCraft> edit(@RequestBody @Valid AirAirCraft airAircraft) {
        AirAirCraft update = airCraftService.update(airAircraft);
        return ResultVo.ok(update);
    }

    @GetMapping("/delete")
    @ApiOperation("根据id删除飞机信息")
    public ResultVo<String> deleteById(String entityId) {
        airCraftService.deleteById(entityId);
        return ResultVo.ok("删除成功");
    }

}

